package com.gexin.controller.xapp.acitivity;

 import com.alibaba.fastjson.JSONObject;
 import com.gexin.common.job.OrderJob;
 import com.gexin.common.model.ApiResponse;
 import com.gexin.core.interceptor.XAppSafeInterceptor;
import com.gexin.core.web.AppController;
import com.gexin.model.activity.*;
 import com.gexin.model.order.Order;
 import com.gexin.model.weixin.WeixinUser;
import com.gexin.service.memberAcitivty.*;
 import com.jfinal.aop.Before;
import com.jfinal.ext.route.ControllerBind;
import com.jfinal.plugin.activerecord.Page;
 import com.jfinal.plugin.activerecord.tx.Tx;

 import java.math.BigDecimal;
import java.util.List;
import java.util.Map;


@Before(XAppSafeInterceptor.class)//统一错误拦截
@ControllerBind(controllerKey = "/xapp/acitiyMember")
public class AcitiyMemberController extends AppController {

    private static final MemberActivityService memberActivityService = new MemberActivityService();

    private CashCouponLog cashCouponLog = new CashCouponLog();



    @Before(Tx.class)
    public void test(){
        Order order = Order.dao.getOrderByOrderId("102111620910081544");
        order.setPayState(7);
        order.setState(78);
        boolean update = order.update();
        System.out.println(update);
    }

    /**
     * MemberIntegralLog
     * 6为签到
     */
    @Before(Tx.class)
    public void taskEveryDay(){
        WeixinUser weixinUser = getAuthUser();
        Integer task = getParaToInt("task",1);
        ApiResponse apiResponse = memberActivityService.taskEveryDay(weixinUser.getId()+"", task);
        renderJson(apiResponse);
        return;
    }



    /**
     * 积分池里的今日总积分以及剩余积分
     */
//    public void getIntegralPool(){
//        IntegralPool integralPool = memberActivityService.getIntegralPool();
//        renderJson(integralPool);
//        return;
//    }


//    public void generalSpeedIntegralDetails(){
//        GeneralSpeedIntegralDetals generalSpeedIntegralDetals = memberActivityService.getDailyIntegralSpeed();
//        renderJson(generalSpeedIntegralDetals);
//        return;
//    }

//    public void getTask(int type){
//        WeixinUser authUser = getAuthUser();
//        memberActivityService.task(authUser.getId()+"",type);
//    }


    /**
     * 购买商品获得积分
     */
    public void buyProductGeneaterIntegral() {
        Integer type = 3;
        Integer integralIncrement = new Integer(2);
        WeixinUser authUser = getAuthUser();
//      integralService.buyGeneralIntegral(authUser, type, BigDecimal.valueOf(integralIncrement));
    }




    /**
     * 积分可兑换的金币
     0代表金币兑换
     1代表兑货券兑换
     */
//    public void integralExchangeAlearyCoin() {
//        int type = getParaToInt("type");
//        String authUser = getAuthUser().getId()+"";
//        ApiResponse apiResponse = memberActivityService.integralExchangeCoin(authUser,type);
//        renderJson(apiResponse);
//        return;
//    }






//    public void tes1t(){
//       OrderJob job = new OrderJob();
//       job.teste();
//    }


//    public void changeMoney(){
//        String money = getPara("balance");
//        String auth = getAuthUser().getId()+"";
//        ApiResponse apiResponse = memberActivityService.coinExchangeMoneyBanck(auth, money);
//        renderJson(apiResponse);
//        return;
//    }


}
